#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n = 1;
    while(cin >> n)
    {
        int ret = 1;
        while(ret - 1 <= n)
        {
            ret *= 2;
        }
        cout << ret / 2 - 1 << endl;
    }
    return 0;
}